<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018\7\17 0017
 * Time: 11:29
 */
namespace model;
use model;
class goodsModel extends model{


    public static function search(){

        $sql = "select * from sh_goods";
        $result = self::$db->query( $sql );

        return $result;

    }

    public static function detail(){

        $sql = "select * from sh_goods where id=1";
        $result = self::$db->query( $sql );

        return $result;

    }

    public static function getImgUrl( $goods_id ){

        $sql = 'select url from sh_goods where is_default=1 and goods_id= ' . $goods_id . ' limit 0,1';
        $result = self::$db->query( $sql );
        return !empty( $result->row ) ? $result->row['url']:'';
    }

    /**
     * @param $data
     * @return string
     * 测试， 之后删掉
     */
    public static function add( $name, $price ){

        $sql = 'insert into sh_goods set price=' . $price .', name="'.$name . '"';
        $result = self::$db->query( $sql );
        return $result;
    }

    /**
     * @param $data
     * @return string
     * 测试， 之后删掉
     */
    public static function delete( $product_id ){

        $sql = 'delete from sh_goods where id=' . $product_id;
        $result = self::$db->query( $sql );
        return $result;
    }

}